/**
 * 
 */
package com.guchenbo.example.jaxb;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.List;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;

import org.apache.commons.io.IOUtils;
import org.eclipse.persistence.jaxb.MarshallerProperties;
import org.eclipse.persistence.jaxb.UnmarshallerProperties;
import org.junit.Before;
import org.junit.Test;

/**
 * @author Cre.Gu
 *
 */
public class JaxbTest {

	Teacher a;
	String xml = "";
	String json = "";

	@Before
	public void setup() {
		a = new Teacher();
		a.setId("1");
		a.setName("name");

		List<String> students = new ArrayList<String>();
		students.add("Jim");
		students.add("Lucy");
		a.setStudents(students);

		xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<teacher>\n"
				+ "    <id>1</id>\n" + "    <name>name</name>\n" + "</teacher>";
		;

		json = "{\n" + "   \"teacher\" : {\n" + "      \"id\" : \"1\",\n"
				+ "      \"name\" : \"name\",\n"
				+ "      \"students\" : [ \"Jim\", \"Lucy\" ]\n" + "   }\n"
				+ "}";
		;
	}

	@Test
	public void xml2Object() throws Exception {
		System.out.println(JaxbUtils.xml2Object(xml, Teacher.class));
		;
	}

	@Test
	public void object2Xml() throws Exception {
		System.out.println(JaxbUtils.object2Xml(a, Teacher.class));
	}

	@Test
	public void json2Object() throws Exception {
		System.out.println(JaxbUtils.json2Object(json, Teacher.class));
		;
	}

	@Test
	public void object2Json() throws Exception {
		System.out.println(JaxbUtils.object2Json(a, Teacher.class));
	}


}
